package pers.gxm.strategy;

public class Player {
    public static void main(String[] args) {
        Player xi = new Player("xi", new WinningStrategy());
        Player ming = new Player("ming", new ProbStrategy());
        for(int i = 0;i < 100000 ;i++){
            Hand xiHand = xi.nextHand();
            Hand mingHand = ming.nextHand();
            System.out.println("xi出" + xiHand );
            System.out.println("ming出" + mingHand );
            if(xiHand.isStrongerThan(mingHand)){
                xi.win();
                ming.lose();
                System.out.println("获胜者是" + xi.name);
            }else if(xiHand.isWeakerThan(mingHand)){
                xi.lose();
                ming.win();
                System.out.println("获胜者是" + ming.name);
            }else{
                System.out.println("平局");
                xi.even();
                ming.even();
            }
        }
        System.out.println("结算结果：");
        System.out.println(xi);
        System.out.println(ming);


    }
    private String name;
    private Strategy strategy;
    private int winCount;
    private int loseCount;
    private int gameCount;
    public Player(String name , Strategy strategy){
        this.name = name;
        this.strategy = strategy;
    }
    public Hand nextHand(){
        return strategy.nextHand();
    }

    public void win(){
        strategy.study(true);
        winCount++;
        gameCount++;
    }

    public void lose(){
        strategy.study(false);
        loseCount++;
        gameCount++;
    }

    public void even(){
        gameCount++;
    }

    @Override
    public String toString() {
        return "Player{" +
                "name='" + name + '\'' +
                ", winCount=" + winCount +
                ", loseCount=" + loseCount +
                ", gameCount=" + gameCount +
                '}';
    }
}
